package com.leviassaf.androidbasics;

import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;

//79
public class SoundStuff extends Activity implements OnClickListener, OnLongClickListener {
	
	SoundPool soundpool;
	int intExplosion = 0;
	//80
	MediaPlayer mediaplayer;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		View view = new View(this);
		view.setOnClickListener(this);
		//80
		view.setOnLongClickListener(this);
		
		setContentView(view);
		soundpool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
		intExplosion = soundpool.load(this, R.raw.explosion, 1);
		//80
		mediaplayer = MediaPlayer.create(this, R.raw.background);

		this.setTitle(String.format("%s-%s", this.getTitle().toString(), this.getClass().getSimpleName()));
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		if (intExplosion != 0){
			soundpool.play(intExplosion, 1, 1, 0, 0, 1);
		}
	}

	@Override
	public boolean onLongClick(View arg0) {
		// TODO Auto-generated method stub
		mediaplayer.start();
		return false;
	}

}
